package ch09.game;

import java.util.Locale;
import java.util.Scanner;

public class TestGame {

    public static void main(String[] args) {
//        int[] position = DataStreamManager.load();
//        Position position = ObjectStreamManager.load();
//        Position position = FileReaderManger.load();
        Position position =FileReaderManger2.load();
        int x = position.getX();
        int y = position.getY();
        System.out.printf("开始位置: x:%d y:%d\n\n",x,y);
        Scanner input = new Scanner(System.in);
        boolean flag = true;
        while(flag) {
            System.out.println("请输入 A:左 D:右 W:上 S:下 I:保存 P:退出");
            String direction = input.next().toUpperCase(Locale.ROOT);
            switch (direction){
                case "A":
                    System.out.println("往左走一步");
                    x -= 1;
                    break;
                case "D":
                    System.out.println("往右走一步");
                    x += 1;
                    break;
                case "W":
                    System.out.println("往上走一步");
                    y -= 1;
                    break;
                case "S":
                    System.out.println("往下走一步");
                    y += 1;
                    break;
                case "I":
                    position.setX(x);
                    position.setY(y);
//                    DataStreamManager.save(position);
//                    ObjectStreamManager.save(position);
//                    FileReaderManger.save(position);
                    FileReaderManger2.save(position);
                    System.out.println("保存成功");
                    break;
                case "P":
                    System.out.println("退出游戏");
                    flag = false;
                    break;
                default:
                    System.out.println("输入有误");
                    break;
            }
            System.out.printf("当前位置: x:%d y:%d\n\n",x,y);
        }
    }
}
